﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Muccu
{
    public class MaxAttribute : ArgumentValidationAttribute
    {
        public MaxAttribute(float value)
        {
            this.Max = value;
            this.ErrorMessage = string.Format("Argument should not be higher than {0}", this.Max);
        }

        public float Max { get; set; }

        public override bool ServerValidate(object value)
        {
            float val = (float)value;
            return val <= Max;
        }

        public override string ClientValidate
        {
            get
            {
                return @"function(val, messages){
var max = " + Max + @"; 
    var isValid = (val <= max);
    if(!isValid)messages.push(""" + ErrorMessage + "\"); return isValid;}";
            }
        }
    }
}
